/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import lejos.nxt.*;

import lejos.robotics.Colors;

/**
 *
 * @author Max
 */
public class ColorSensorChew
{

    private final int portNo = 0;
    private ColorLightSensor cs;
    private int colorNo;
    int[] colors = new int[3];

    /**
     * Creates obeject and sets type of ColorSensor
     */
    public ColorSensorChew()
    {
        cs = new ColorLightSensor(SensorPort.PORTS[portNo], ColorLightSensor.TYPE_NO_SENSOR);
        cs.setType(ColorLightSensor.TYPE_COLORFULL);
    }

    /**
     * Reads the value of the Color and stores it in a variable
     * If color is white, it checks if it is not yellow
     *
     */
    public void readColor()
    {

        colorNo = cs.readValue();
        colors = cs.getColor();
        if (isColorWhite())
        {
            if (colors[1] > 185 && colors[1] < 250 && colors[2] > 110 && colors[2] < 160)//&&colors[3]<50)
            {
                colorNo = Colors.YELLOW;
            }
        }
    }

    /**
     *
     * @return true if color is red
     */
    public boolean isColorRed()
    {

        return colorNo == Colors.RED;
    }

    /**
     *
     * @return true if color is blue
     */
    public boolean isColorBlue()
    {
        return colorNo == Colors.BLUE;


    }

    /**
     *
     * @return true if color is yellow
     */
    public boolean isColorYellow()
    {
        return colorNo == Colors.YELLOW;

    }

    /**
     *
     * @return true if color is white
     */
    public boolean isColorWhite()
    {
        return colorNo == Colors.WHITE;

    }

    /**
     *
     * @return true if color is black
     */
    public boolean isColorBlack()
    {
        return colorNo == Colors.BLACK;

    }

    /**
     *
     * @return true if color is green
     */
    public boolean isColorGreen()
    {
        return colorNo == Colors.GREEN;

    }
}
